The present disclosure relates to compiler optimization, and more specifically, to a technique for inlining code.
Inlining is a technique in which code defined by a method or function is expanded and embedded directly at the site where it was called, and is one of the most effective compiler optimization techniques. Inlining can reduce call/return overhead, expand the optimization range, and improve the spatial locality of the code. However, excessive inlining can increase cache misses and increase compilation times.
One technique for suppressing inlining involves a threshold value. When this technique is used, the inlining threshold value is determined so as to take into account the tradeoffs mentioned above and to establish a balance between the costs and benefits of inlining. However, because the threshold value determined in this way is applied to a static footprint (that is, to a footprint including code that is not actually run), the size of the actual footprint (that is, the size of the code that is actually run) cannot be effectively reduced. For example, there is a possibility that a method with a large static footprint in which only some of the code is run will not be inlined, and the method will perform poorly because of the call overhead.
Another technique involves an optimum inline threshold value that is calculated using machine learning. This technique is beneficial when a compiler developer tune inlining threshold values. However, the computational cost of machine learning is high, and is difficult to apply to dynamic compilation.
Yet another technique involves inserting instrumented code into a program, collecting profile information to identify call frequencies, and using the collected profile information to perform efficient inlining during recompiling.
Still another technique involves extracting common elements of a program on the basis of an execution trace, and determining, based on the number of times an instruction is actually run, whether or not the common elements are to be assembled as one element.
Yet another technique involves estimating the actual footprint after inlining on the basis of instruction execution frequency. When using this technique, instrumented code is inserted into a program, and the average execution frequency is obtained each time the basic blocks in the loop have been repeated. Then, the actual footprint of the loop is obtained using the number of instructions inside the basic blocks and their execution frequency.
However, inserting instrumented code into programs and using execution traces have a high profile overhead and are difficult to apply to dynamic compilation.